package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.kaishengit.entity.User;
import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class CustomerDao {
	private  DBHelp<User>  db = new  DBHelp<User>();
	
	public User findByNameAndPwd(String name,String pwd){
		String sql = "SELECT id,name,pwd ,role FROM t_user WHERE name=? AND pwd=?";
		User user=db.executeForObject(sql, new UserRowMapper(), name,pwd);
		return user;
		
	}
	public List<User>  findName(String name){
		String sql="SELECT id,name,pwd ,role FROM t_user WHERE name LIKE ?";
		List<User> list = db.executeForList(sql, new UserRowMapper(), name+"%");
		return list;
	}
	public class UserRowMapper  implements RowMapper<User>{

		public User mapperRow(ResultSet rs) throws SQLException {
			User u = new User();
			u.setId(rs.getInt("id"));
			u.setName(rs.getString("name"));
			u.setPwd(rs.getString("pwd"));
			u.setRole(rs.getString("role"));
			return u;
		}
		
	}
}
